package main

import (
	"accounting-software/conf"
	"accounting-software/controllers"
	"accounting-software/dao"
	"accounting-software/routers"
	"accounting-software/services"

	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
)

func main() {
	// 初始化数据库
	conf.InitDB()
	// 实例化dao层
	userDao := dao.NewUserDao(conf.DB)
	// 实例化service层
	userService := services.NewUserService(userDao)

	// 实例化controller层
	userController := controllers.NewUserController(userService)

	// 创建 Gin 路由引擎
	router := gin.Default()

	// 配置 CORS 中间件
	config := cors.DefaultConfig() // 使用默认配置
	config.AllowAllOrigins = true  // 允许所有来源
	config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}
	config.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "Authorization"}
	// 使用上面设置的配置
	router.Use(cors.New(config))

	// 设置路由
	routers.SetupUserRoutes(router, userController)

	// 启动服务器
	router.Run(":8088")

}
